From 34e07ec85446398069ea2942a7eccb676ea1512d Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Sat, 19 Aug 2017 03:53:57 +0200 Subject: [PATCH] babl: add handling of BABL_RGB_OVERRIDE environment variable --- babl/babl-space.c | 37 ++++++++++++++++++++++++++++--------- babl/babl.h | 2 +- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/babl/babl-space.c b/babl/babl-space.c index e6ef5ed..37c40ad 100644 --- a/babl/babl-space.c +++ b/babl/babl-space.c @@ -213,23 +213,42 @@ babl_space_class_for_each (BablEachFunction each_fun, void babl_space_class_init (void) { - /* we register sRGB first so that lookups for it is fastest */ -#ifdef CCE - babl_space_rgb_chromaticities ("sRGB", - 0.3127, 0.3290, /* D65 */ + if (getenv ("BABL_RGB_OVERRIDE")) + { + /* added to be able to easily have the behavior of Elle Stones CCH fork of babl, + * configuring the working space through an environment variable should be easier + * than keeping compiled versions of CCH GIMP for different spaces. + */ + + char *override = getenv ("BABL_RGB_OVERRIDE"); + if (strlen (override) < 5) + { + babl_space_rgb_chromaticities ("sRGB", + 0.3127, 0.3290, /* D65 */ 0.6400, 0.3300, 0.3000, 0.6000, 0.1500, 0.0600, babl_trc("linear"), NULL, NULL); -#else - babl_space_rgb_chromaticities ("sRGB", + } + else + { + float xr=0.6400, yr=0.3300, xg=0.3000, yg=0.6000, xb=0.1500, yb=0.0600, wx=0.3127, wy=0.3290, gamma=2.2; + sscanf (override, "%f %f %f %f %f %f %f %f %f", &xr, &yr, &xg, &yg, &xb, &yb, &wx, &wy, &gamma); + fprintf (stderr, "overriding babl default RGB space with: r=%f %f g=%f %f b=%f %f w=%f %f gamma=%f\n", + xr, yr, xg, yg, xb, yb, wx, wy, gamma); + babl_space_rgb_chromaticities ("sRGB", + wx, wy, xr, yr, xg, yg, xb, yb, babl_trc_gamma (gamma), NULL, NULL); + } + } + else + { + babl_space_rgb_chromaticities ("sRGB", 0.3127, 0.3290, /* D65 */ - //0.3127, 0.3290, /* D65 */ 0.6400, 0.3300, 0.3000, 0.6000, 0.1500, 0.0600, babl_trc("sRGB"), NULL, NULL); -#endif + } babl_space_rgb_chromaticities ( "Adobe", @@ -330,7 +349,7 @@ void babl_space_from_xyz (const Babl *space, const double *xyz, double *rgb) _babl_space_from_xyz (space, xyz, rgb); } -double * babl_space_get_rgbtoxyz (const Babl *space) +const double * babl_space_get_rgbtoxyz (const Babl *space) { return space->space.RGBtoXYZ; } diff --git a/babl/babl.h b/babl/babl.h index e24640e..b635c00 100644 --- a/babl/babl.h +++ b/babl/babl.h @@ -122,7 +122,7 @@ const Babl * babl_space_rgb_chromaticities (const char *name, const Babl *trc_green, const Babl *trc_blue); -double * babl_space_get_rgbtoxyz (const Babl *space); +const double * babl_space_get_rgbtoxyz (const Babl *space); void babl_space_to_xyz (const Babl *space, const double *rgb, double *xyz); void babl_space_from_xyz (const Babl *space, const double *xyz, double *rgb); -- 2.30.2